pp108 : onexpand Property

onexpand Property

This is an optional property that contains the pointer to a function to be to be called when an item in the tree is expanded.

Syntax

XML

<TreeItem>
    <searchPath>sName</searchPath>
    <description>sDesc</description>
    <onexpand>fpFunction</onexpand>
        ...
        ...
        ...
</TreeItem>

Parameters

Parameter

Description

fpFunction

Pointer to a function that is to be called when an item in the tree is expanded.

Remarks

Once this property is set to a tree item, the item will become a node (item with a "+" symbol before it indicating that it can be expanded to one level).

The function associated with the event will be fired when the "+" icon in the tree item is clicked. This can be used to add tree items to the expanded node. Once an item in expanded, it will have a "-" symbol in place of "+" indicating that the item is already expanded.

If the return value of the function is set to 'false', then the item will not be expanded.

Example

The following example shows how the property is used.

<!-- Schema for tree. "expandHandler" is a function that will be called when item is expanded -->
<script type="cordys/xml" id="schema">
    <TreeSchema>
        <searchPath>//data/tuple/old/</searchPath>
        <Root>
            <description>Employees</description>
        </Root>
        <TreeItem id="EmployeesID">
            <searchPath>Employees</searchPath>
            <description>FirstName</description>
            <onexpand>expandHandler</onexpand>
        </TreeItem>
    </TreeSchema>
</script>
//Function call
function expandHandler(expandedNode)
{
    <!-- Alert data of the expanded item -->
    application.notify("item expanded : " + cordys.getXML(expandedNode.data));

    <!-- Return without expanding -->
    return false;
}
<!-- tree definition -->
<div cordysType="wcp.libaray.ui.Tree"  id="sampleTree" treeSchema="schema" treeData="data"></div>

See Also

tree